import { Component, OnInit } from '@angular/core';
import { ContractService } from "./contract-account.service";
import { DataService } from '../../../../services/data.service';
import * as _ from 'lodash';

@Component({
  selector: 'app-contract-account',
  templateUrl: './contract-account.component.html',
  styleUrls: ['./contract-account.component.scss'],
  providers: [ContractService]
})
export class ContractAccountComponent implements OnInit {
  public optionModel: any = '1';
  // 字典值
  public dictionaryList: any = {};
  // 产品类型
  public sFundType: any = [];
  // 合同信息
  public contractBody: any = {};
  //条目内容
  public entryInfo: any = {};
  constructor(
    public contractService: ContractService,
    public dataService: DataService
  ) { }

  ngOnInit() {
    this.getSingleServiceInfo();
    // 字典值
    this.dictionaryList = JSON.parse(localStorage.getItem("dictionaryList"));
    // 产品类型
    this.sFundType = _.filter(this.dictionaryList.FUND_TYPE, function (item: any) {
      return item.sItemKey > 3 && item.sItemKey < 8;
    })
  }
  //查询-单个核算条目条目内容（根据FundNo）
  getSingleServiceInfo() {
    this.contractService.getSingleInfo(this.contractBody.nFundNo).subscribe(data => {
      if (data) {
        this.entryInfo = data;
        // console.log("------------sadasd---------------")
        // console.log(data);
      }
    })
  }
  //更新-核算条目-单个
  editAccountEntry() {
    let that = this;
    window["swal"]({
      title: "注意",
      text: "是否确定保存条目",
      type: "warning",
      confirmButtonText: "确认",
      cancelButtonText: "取消",
      showCancelButton: true,
      closeOnConfirm: false,
      closeOnCancel: true,
      showLoaderOnConfirm: true
    },
      function (isConfirm) {
        if (isConfirm) {
          that.contractService.edit(that.entryInfo).subscribe(data => {
            if (data) {
              that.dataService.entryEmitter.emit('contractAccount');
              window['swal']("提示", "修改条目成功!", "success");
            }
          })
        }
      })
  }
}
